
<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="18" :xs="24">
        <el-card>
          <div slot="header" class="clearfix">
            <span>店铺配置</span>
          </div>
          <el-form ref="dataForm" :rules="rules" :model="dataForm" label-width="100px">
            <el-form-item label="店铺名称" prop="litemall_mall_name">
              <el-input v-model="dataForm.litemall_mall_name" :style="{width: '60%'}"/>
            </el-form-item>
            <el-form-item label="店铺地址" prop="litemall_mall_address">
              <el-input v-model="dataForm.litemall_mall_address" :style="{width: '60%'}"/>
            </el-form-item>
            <el-form-item label="地理坐标">
              <el-col :span="6">
                <el-input v-model="dataForm.litemall_mall_longitude" placeholder="经度"/>
              </el-col>
              <el-col :span="2" style="text-align: center;">-</el-col>
              <el-col :span="6">
                <el-input v-model="dataForm.litemall_mall_latitude" placeholder="纬度"/>
              </el-col>
            </el-form-item>
            <el-form-item label="联系电话" prop="litemall_mall_phone">
              <el-input v-model="dataForm.litemall_mall_phone" :style="{width: '60%'}"/>
            </el-form-item>
            <el-form-item label="QQ交流群" prop="litemall_mall_qq">
              <el-input v-model="dataForm.litemall_mall_qq" :style="{width: '60%'}"/>
            </el-form-item>
            <el-form-item>
              <el-button @click="cancel">取消</el-button>
              <el-button type="primary" @click="update">确定</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { listMall, updateMall } from '@/api/config'

export default {
  name: 'ConfigMail',
  data() {
    return {
      dataForm: {
        litemall_mall_name: '',
        litemall_mall_address: '',
        litemall_mall_phone: '',
        litemall_mall_qq: '',
        litemall_mall_longitude: '',
        litemall_mall_latitude: ''
      },
      rules: {
        litemall_mall_name: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        litemall_mall_address: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        litemall_mall_phone: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        litemall_mall_qq: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.init()
  },
  methods: {
    init: function() {
      listMall().then(response => {
        this.dataForm = response.data.data
      })
    },
    cancel() {
      this.init()
    },
    update() {
      this.$refs['dataForm'].validate((valid) => {
        if (!valid) {
          return false
        }
        this.doUpdate()
      })
    },
    doUpdate() {
      updateMall(this.dataForm)
        .then(response => {
          this.$notify.success({
            title: '成功',
            message: '店铺配置成功'
          })
        })
        .catch(response => {
          this.$notify.error({
            title: '失败',
            message: response.data.errmsg
          })
        })
    }
  }
}
</script>
